package com.threadLocal;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.concurrent.TimeUnit;

/**
 * Created by huangyugen on 2019/05/14
 **/
public class InstantTest {

    public static void main(String[] args) {
        Instant utcNow = Instant.now();
        System.out.println("原生时间："+utcNow);//UTC时间

        //转化为北京时间
        Instant now = Instant.now().plusMillis(TimeUnit.HOURS.toMillis(8));
        System.out.println("北京时间:"+now);

        System.out.println("秒数:"+now.getEpochSecond());
        System.out.println("毫秒数:"+now.toEpochMilli());


        LocalDateTime localDateTime = LocalDateTime.now();
        System.out.println(localDateTime.toLocalDate());
        //LocalDateTime转Instant
        Instant localDateTime2Instant = localDateTime.atZone(ZoneId.systemDefault()).toInstant();
        System.out.println("LocalDateTime 毫秒数:"+localDateTime2Instant.toEpochMilli());
    }
}
